<?php
// +----------------------------------------------------------------------
// | Item
// +----------------------------------------------------------------------
// | Copyright
// +----------------------------------------------------------------------
// | Versions
// +----------------------------------------------------------------------
// | Author       YanHao
// +----------------------------------------------------------------------
// | Date
// +----------------------------------------------------------------------

namespace app\admin\modeldata;

use think\Db;

class AuthRule
{
    const TABLE = 'tp_auth_rule';

    public static $rule = [
        '权限管理' => [
            ['name'=>'Admin/adminLists', 'title'=>'查看系统管理员' ],
            ['name'=>'Admin/createUser', 'title'=>'查看管理员详情' ],
            ['name'=>'Admin/addUser', 'title'=>'添加/修改系统管理员' ],
            ['name'=>'Admin/setUserStatus', 'title'=>'设置管理员状态'],
            ['name'=>'Admin/userDelete', 'title'=>'删除管理员'],
            ['name'=>'Admin/groupLists', 'title'=>'查看用户组'],
            ['name'=>'Admin/createUserGroup', 'title'=>'查看用户组详情'],
            ['name'=>'Admin/editUserGroup', 'title'=>'添加/修改用户组'],
            ['name'=>'Admin/setUserGroupStatus', 'title'=>'设置用户组状态'],
            ['name'=>'Admin/userGroupDelete', 'title'=>'删除用户组'],
        ],
        '会员管理'=> [
            ['name'=>'Member/memberLists', 'title'=>'会员列表'],
        ]
    ];
    /**
     * 导入数据库
     */
    public static function run()
    {
        Db::execute("TRUNCATE TABLE ". self::TABLE);
        $rules = [];
        foreach (self::$rule as $group=>$lists) {
            foreach ($lists as $v) {
                $rules[] = $v;
            }
        }
        return Db::table(self::TABLE)->insertAll($rules) ? true : false;
    }
    /**
     * 查询所有数据 
     * @return array
     */
    public static function all()
    {
        return Db::table(self::TABLE)->field(true)->select();
    }

    public static function getKeyIndex()
    {
        return Db::table(self::TABLE)->column('id', 'name');
    }

}